package ltd.dujiabao.capability.domain.rulemng.expression;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/13 12:26
 * @Desc :
 */
public enum ExpressionType {
    /**
     * 相等
     */
    EQUALS("=", EqualsExpression.class),
    /**
     * 模糊匹配
     */
    LIKE("like", LikeExpression.class),
    /**
     * 以..开头
     */
    STARTS_WITH("startsWith", StartsWithExpression.class),
    /**
     * 以..结束
     */
    ENDS_WITH("endsWith", EndWithExpression.class),
    /**
     * 正则匹配
     */
    REGEX("regex", RegexWithExpression.class);

    private final String sign;

    private final Class<? extends Expression> expressionClass;
    private static final Map<String, ExpressionType> VALUE_MAP = new HashMap<>();

    static {
        for (ExpressionType expressionType : values()) {
            VALUE_MAP.put(expressionType.sign, expressionType);
        }
    }

    ExpressionType(String sign, Class<? extends Expression> expressionClass) {
        this.sign = sign;
        this.expressionClass = expressionClass;
    }

    public static ExpressionType parse(String sign) {
        return VALUE_MAP.get(sign);
    }

    public Class<? extends Expression> getExpressionClass() {
        return expressionClass;
    }
}
